// pages/casual/casual.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    maskShow: false,
    gymID: '',
    playData: {},
    messErr: '',
    resultData: '',
    lmessSucc: false,
    lerrCode: false,
    lsuccCode: false,
    closeData: {},
    onlyTf: false,
    // 临时
    tempData: '',
  },
  // 临时扫码开门
  scanCode: function () {
    var that = this;
    wx.scanCode({
      onlyFromCamera: true,
      success: (res) => {
        console.log(res, "res")
        this.setData({
          resultData: res.result
        });
        let apiURL = '';
        var regIn = RegExp(/in/);
        var regOut = RegExp(/out/);
        if (res.result.match(regIn)) {
          apiURL = "https://jd.trc-demo.com/api/v1/app/gym/tempIn?"
        } else if (res.result.match(regOut)) {
          apiURL = "https://jd.trc-demo.com/api/v1/app/gym/tempOut?"
        }
        // console.log(apiURL)
        wx.request({
          url: apiURL + res.result,
          method: 'GET',
          data: {
          },
          header: {
            'content-type': 'application/json',
            'Authorization': wx.getStorageSync('token_type') + ' ' + wx.getStorageSync('access_token'),
          },
          success: function (res) {
            if (res.data.resultCode == 400){
              that.setData({
                lmessSucc: false,
                lerrCode: true,
                messErr: res.data.resultMessage,
              })
            } else if (res.data.resultCode == 300) {
              that.setData({
                lmessSucc: true,
                lerrCode: true,
                messErr: res.data.resultMessage,
              })
            }
            console.log(res,"lins")
          }
        })
      }
    })
  },
  // 关闭扫码弹窗
  celErr: function () {
    this.setData({
      lerrCode: false,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})